var toolbarMenutoggle = 0;
var toolbarRootView = 0;
var toolbarRootView = 0;
var toolSettingsView = 0;
var settingsMenutoggle = 0;
var settingsViewList = 0;
var settingsRootView = 0;

function enableSettingsMenu()
{
    toolSettingsView = document.createElement("div");
    toolSettingsView.style.position = "absolute";    
    toolSettingsView.className = 'toolbarSettingsView';
    toolSettingsView.onclick = settingsButton;    
    toolSettingsView.style.left = uiWidth - 50;   
    toolSettingsView.style.top = 0;
    toolSettingsView.style.width = 40;
    toolSettingsView.style.height = 40; 
    toolSettingsView.style.backgroundColor = "#9e9e9e"; 
    toolSettingsView.style.overflow = "hidden"; 
    toolSettingsView.innerHTML = "<img width=40 src=\""+CurrentThemeIconPath+"/settings.png\" >";       
    toolRootView.appendChild(toolSettingsView); 

    settingsRootView = document.createElement("div");
    settingsRootView.style.position = "absolute";    
    settingsRootView.className = 'toolbarView';
    settingsRootView.style.left = uiWidth - 100;   
    settingsRootView.style.top = 40; 
    settingsRootView.style.width = 100;	
    settingsRootView.style.backgroundColor ="#9e9e9e"; 
    settingsRootView.style.overflow = "hidden"; 
	settingsRootView.style.visibility = "hidden";	
    uiRootView.appendChild(settingsRootView);	
	
	settingsViewList = document.createElement("ul");
    settingsViewList.style.position = "relative";
    settingsViewList.style.margin = "0";
    settingsViewList.style.padding = "0";
    settingsViewList.style.top = 10; 
    settingsViewList.style.width = 300;    
    settingsViewList.style.left = uiWidth / 2 - 150; 
    settingsViewList.style.listStyle = "none";      
    settingsViewList.style.textDecoration = "none";
    settingsViewList.style.overflow = "hidden";    
    settingsViewList.style.backgroundColor = "0x9a9a9a";  
    settingsRootView.appendChild(settingsViewList);
	
	addSettingsItem("Settings",themeGo);
	addSettingsItem("Tv",facadeGo);
	addSettingsItem("Desktop",desktopGo);
	addSettingsItem("Mobile",mobileGo);
};

function aboutGo()
{
	toolBarOff();
	execJS(rootPath+"/system/bin/about/main.js");
};

function loginGo()
{
	toolBarOff();	
	
	execJS(rootPath+"/system/bin/login/main.js");	
	enableSettingsMenu()
};

function themeGo()
{
	settingsBarOff();	
};

function facadeGo()
{
	settingsBarOff();
	facadeMain("tv");
};

function desktopGo()
{
	settingsBarOff();

	execJS(rootPath+"/system/bin/desktop/main.js");	
};

function mobileGo()
{
	settingsBarOff();
	facadeMain("mobile");
};

function settingsGo()
{
	settingsBarOff();
	execJS(rootPath+"/system/bin/settings/main.js");
};

function testGo()
{
	toolBarOff();
	execJS(rootPath+"/system/bin/test/main.js");
};

function addSettingsItem(name,action)
{
    this.myID = document.createElement("li");
    this.myID.style.position = "relative";
    this.myID.id = name;
    this.myID.style.margin = "auto";
    this.myID.style.padding = "0";
    this.myID.style.textDecoration = "none";
    this.myID.style.fontSize = "30px";
    this.myID.style.borderColor = "0x00ff00";
    this.myID.style.listStyle = "none";  
    this.myID.style.backgroundColor = "0x9a9a9a";    
    this.myID.innerHTML = name; 
    this.myID.onclick = action;
    this.myID.onmouseover = function(){  document.getElementById(name).style.border =  "3px blue solid"; };  
    this.myID.onmouseout = function(){ document.getElementById(name).style.border = "0px black solid";};
    settingsRootView.appendChild(this.myID);
};

function addMenuItem(name,action)
{
    this.myID = document.createElement("li");
    this.myID.style.position = "relative";
    this.myID.id = name;
    this.myID.style.margin = "auto";
    this.myID.style.padding = "0";
    this.myID.style.textDecoration = "none";
    this.myID.style.fontSize = "30px";
    this.myID.style.borderColor = "0x00ff00";
    this.myID.style.listStyle = "none";  
    this.myID.style.backgroundColor = "0x9a9a9a";    
    this.myID.innerHTML = name; 
    this.myID.onclick = action;
    this.myID.onmouseover = function(){  document.getElementById(name).style.border =  "3px blue solid"; };  
    this.myID.onmouseout = function(){ document.getElementById(name).style.border = "0px black solid";};
    toolbarRootView.appendChild(this.myID);
};

function toolInit()
{
    toolbarRootView = document.createElement("div");
    toolbarRootView.style.position = "absolute";    
    toolbarRootView.className = 'toolbarView';
    toolbarRootView.style.left = 0;   
    toolbarRootView.style.top = 40; 
    toolbarRootView.style.backgroundColor ="#9e9e9e"; 
    toolbarRootView.style.overflow = "hidden"; 
    toolbarRootView.style.visibility = "hidden";	
	document.getElementById("toolbar").appendChild(toolbarRootView); 

    toolbarViewList = document.createElement("ul");
    toolbarViewList.style.position = "relative";
    toolbarViewList.style.margin = "0";
    toolbarViewList.style.padding = "0";
    toolbarViewList.style.top = 10; 
    toolbarViewList.style.width = 300;    
    toolbarViewList.style.left = uiWidth / 2 - 150; 
    toolbarViewList.style.listStyle = "none";      
    toolbarViewList.style.textDecoration = "none";
	
    toolbarViewList.style.overflow = "hidden";    
    toolbarViewList.style.backgroundColor = "0x9a9a9a";  
    toolbarRootView.appendChild(toolbarViewList);
	
	addMenuItem("About Softsurve",aboutGo);
	addMenuItem("Login",loginGo);
	addMenuItem("Test",testGo);
};

function toolBarOff()
{
    toolbarRootView.style.visibility = "hidden";
	toolbarMenutoggle = 0;
};

function toolBarOn()
{
    toolbarRootView.style.visibility = "visible"; 	
};

function toolbarButton()
{	
	if(!toolbarMenutoggle)
	{
		toolbarMenutoggle = 1;
		toolBarOn();
	}
    else
	{
		toolbarMenutoggle = 1;
		toolBarOff();
	}
};

function settingsBarOff()
{
    settingsRootView.style.visibility = "hidden";
	settingsMenutoggle = 0;
};

function settingsBarOn()
{
    settingsRootView.style.visibility = "visible"; 	
};

function settingsButton()
{	
	if(!settingsMenutoggle)
	{
		settingsMenutoggle = 1;
		settingsBarOn();
	}
    else
	{
		settingsMenutoggle = 1;
		settingsBarOff();
	}
};